<?php
$IP=$_SERVER['REMOTE_ADDR'];
echo $IP;
function IP2Country($ipAddr)
{
// 72.167.131.121
// 71.6.131.6
// 82.244.68.106
$location = $ipAddr;
$q = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&location='.rawurlencode($location);

// $ch = curl_init($q);
// curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
// curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($q)); // use HTTP POST to send form data
// $resp = curl_exec($ch); //execute post and get results
// curl_close ($ch);

$resp=file_get_contents($q);
$xml = simplexml_load_string($resp);
//echo "country -----".$xml->Result[0]->Country;
//echo "<br>State----".$xml->Result[0]->State;/
//echo "<br>City----".$xml->Result[0]->City;
return $xml->Result[0]->Country;
}

//Example :
/*
$IP='82.244.68.106';
$IP='72.167.131.121';
$IP='71.6.131.6';*/

echo $counName=IP2Country($IP);


?>